package com.aaa.controller;

import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
import com.aaa.entity.Result;
import com.aaa.service.DeptService;
import com.aaa.service.UserService;
import com.aaa.service.impl.DeptServiceImpl;
import com.aaa.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/8/9 9:20
 * @description：用户业务控制器
 * @modified By：
 * @version: 1.0
 */
@WebServlet("/dept")
public class DeptController extends BaseController {
  /*  DeptService deptService = new DeptServiceImpl();*/
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //加载spring容器
        ApplicationContext ac= (ApplicationContext) getServletContext().getAttribute("ac");
        DeptService deptService=ac.getBean("deptServiceImpl",DeptService.class);
        //从基类中调用通用的获取参数的方法
        Map map = super.getParams(req);
        System.out.println(map);
        Result result=null;
        //获取method的参数值
        String method = map.get("method") + "";
        switch (method) {
            case "add":
                break;
            case "delete":
                break;
            case "update":
                break;
            case "toUpdate":
                break;
            case "queryUserByName":
                break;
            default:
                //默认是查询所有
                List<Map<String, Object>> mapList = deptService.queryAll(map);
                result = new Result(0,"",deptService.queryCount(map),mapList);
                break;
        }

        super.responseJson(result,resp);
    }

}
